package saeildamil.ch18.critical;

public class PrintThread extends Thread {
	SharedAccount sharedAccount;

	public PrintThread(SharedAccount sharedAccount) {
		this.sharedAccount = sharedAccount;
	}
	
	@Override
	public void run() {
		//이몽룡, 성춘향 계좌 잔액 합계 계산 3번 반복
		int sum=0;
	
		for (int i = 0; i < 3; i++) {
			synchronized (sharedAccount) {

				sum = sharedAccount.leeAccount.balance
						+ sharedAccount.sungAccount.balance;
				System.out.println("=====걔좌 잔액 합계:" + sum + "=====");
			}
			try {
				sleep(1);
			} catch (InterruptedException e) {
				System.out.println(e.getMessage());
			}
		}
	}
}
